    var getService = function(onSuccess,onFailure){
    
            var login = function(service){
                      if(service.$loggedIn)  return;
                      log("check: loggin start")
                      var url = 'http://docs.google.com/feeds/documents/private/full';
                    var callback = function(response){
                        if(response.oauthApprovalUrl){
                                log("check 4 : oauth request token");
                                var popup = shindig.oauth.popup({
                                destination: response.oauthApprovalUrl,
                                windowOptions: 'height=600,width=800',
                                onOpen: function() {
                                  showOnly("waiting");
                                },
                                onClose: function() {
                                  login(service);  
                                  log("close")                      
                                  showOnly("loading");
                                }
                              });
                              document.getElementById('personalize').onclick = popup.createOpenerOnClick();
                              document.getElementById('approvalLink').onclick = popup.createApprovedOnClick();
                              showOnly("approval");                 
                        }
                        else if(response.feed){
                                log("authorized")
                                service.$loggedIn = true;
                                showOnly("main");
                                onSuccess(service, response.feed)    
                        }else{                        
                                log("error: "+response.toString())
                                showOnly("error");
                                onFailure(response);
                        }
                    }
            service.getFeed(url,callback,callback);                
        }     
              var service = new google.gdata.client.GoogleService('writely','gappr1');
              service.useOAuth('google');  
              login(service);
     }   
  }